package jdbc;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class PWDDemo {
    public static void main(String[] args) {
        String userName;
        String nickName;
        String passWord;
        int age;
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入修改的用户:");
        userName =sc.nextLine();
        System.out.println("输入昵称:");
        nickName = sc.nextLine();
        System.out.println("请输入密码:");
        passWord = sc.nextLine();
        System.out.println("请输入年龄:");
        age=Integer.parseInt(sc.nextLine());

        try (Connection conn = DBUtil.getConnection()){
            String sql = "update user set nickname='" +nickName+
                    "',age=" +age+
                    " ,password ='"+passWord+"' where username ='"+userName+"'";

            Statement statement = conn.createStatement();
            int num =statement.executeUpdate(sql);
            System.out.println(num>0?"更新成功":"更新失败");
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }


    }
}
